home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / dev / c / MemPools1_2.lha / mempools / free.c < prev    next >
C/C++ Source or Header  |  1995-05-22  |  2KB  |  94 lines

  1. /**
  2. ***  MemPools:  malloc() replacement using standard Amiga pool functions.
  3. ***  Copyright  (C)  1994    Jochen Wiedmann
  4. ***
  5. ***  This program is free software; you can redistribute it and/or modify
  6. ***  it under the terms of the GNU General Public License as published by
  7. ***  the Free Software Foundation; either version 2 of the License, or
  8. ***  (at your option) any later version.
  9. ***
  10. ***  This program is distributed in the hope that it will be useful,
  11. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ***  GNU General Public License for more details.
  14. ***
  15. ***  You should have received a copy of the GNU General Public License
  16. ***  along with this program; if not, write to the Free Software
  17. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ***
  19. ***
  20. ***  This file contains the malloc() replacement.
  21. ***
  22. ***
  23. ***  Computer:  Amiga 1200
  24. ***
  25. ***  Compilers: Dice 3.01
  26. ***             SAS/C 6.50
  27. ***             gcc 2.6.1
  28. ***
  29. ***
  30. ***  Author:    Jochen Wiedmann
  31. ***             Am Eisteich 9
  32. ***       72555 Metzingen
  33. ***             Germany
  34. ***
  35. ***             Phone: (0049) 7123 14881
  36. ***             Internet: jochen.wiedmann@uni-tuebingen.de
  37. **/
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.     Include files and compiler specific stuff
  44. */
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <proto/exec.h>
  48. #include <clib/alib_protos.h>
  49.  
  50. #include "mempools.h"
  51.  
  52.  
  53.  
  54. #ifdef DEBUG
  55. #define ADDSIZE (sizeof(memBlock)+sizeof(memBlockEnd))
  56. #else
  57. #define ADDSIZE (sizeof(memBlock))
  58. #endif
  59.  
  60.  
  61. void free(void *block)
  62.  
  63. {
  64.     memBlock *ptr;
  65.  
  66.     if ((ptr = block)) {
  67.     size_t size;
  68.  
  69.     ptr = ptr - 1;
  70.     size = ptr->size;
  71. #ifdef DEBUG
  72.     {
  73.         memBlockEnd *eptr;
  74.  
  75.         eptr = (memBlockEnd *) (((char *)(ptr+1))+size);
  76.  
  77.         if (ptr->realSize != size + ADDSIZE                         ||
  78.         memcmp(ptr->lowerBoundary, meatBeaf, sizeof(meatBeaf))  ||
  79.         memcmp(eptr->upperBoundary, meatBeaf, sizeof(meatBeaf))) {
  80.         extern void kprintf(const char *, ...);
  81.  
  82.         kprintf("Danger: Memory destroyed at %08lx.\n", ptr+1);
  83.         exit(0);
  84.         }
  85.  
  86.         memset(ptr->lowerBoundary, '\0', sizeof(meatBeaf));
  87.         memset(eptr->upperBoundary, '\0', sizeof(meatBeaf));
  88.     }
  89.     Remove((struct Node *) ptr);
  90. #endif
  91.     LibFreePooled(__MemPool, ptr, size + ADDSIZE);
  92.     }
  93. }
  94.